import AccessEnum from "@/access/AccessEnum";

const checkAccess = (loginUser: any, needAccess = AccessEnum.NOT_LOGIN) => {
  const loginUserAcess = loginUser?.userRole ?? AccessEnum.NOT_LOGIN;

  if (needAccess === AccessEnum.NOT_LOGIN) {
    return true;
  }

  if (needAccess === AccessEnum.USER) {
    if (loginUserAcess === AccessEnum.NOT_LOGIN) {
      return false;
    }
  }
  if (needAccess === AccessEnum.ADMIN) {
    if (loginUserAcess !== AccessEnum.ADMIN) {
      return false;
    }
  }
  return true;
};

export default checkAccess;
